package com.edu.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Date;

@Aspect
@Component
public class myAspect {
    @Pointcut("execution(* com.edu.mapper..select*(..))")
    public void pt1(){}
    @Pointcut("execution(* com.edu.mapper..delete*(..))")
    public void pt2(){}
    @Pointcut("execution(* com.edu.mapper..insert*(..))")
    public void pt3(){}
    @Before("pt2() || pt3()")
    public void before(JoinPoint jt){
        System.out.println("前置通知"+jt.getSignature().getName()+"开始时间为："+new Date());
    }
    @After("pt2() || pt3()")
    public void after(JoinPoint jt){
        System.out.println("后置通知"+jt.getSignature().getName()+"结束时间为："+new Date());
    }
    @Around("pt1()")
    public Object  around(ProceedingJoinPoint pjt) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = pjt.proceed();
        long end = System.currentTimeMillis();
        System.out.println("查询运行时间"+(end-start));
        return result;
    }

}
